/*
 * @Description: 数组形成大根堆
 * @Author: your name
 * @Date: 2019-08-19 16:30:14
 * @LastEditTime: 2019-08-19 16:30:26
 * @LastEditors: Please set LastEditors
 */
const heapSort = function(arr){
    if(arr.length < 2 ||arr == null){
        return arr
    }
    for(let i=0;i<arr.length;i++){
        heapInsert(arr,i)
    }
    return arr
}

function heapInsert(arr,index){
    if(index >= 0){
        while(arr[Math.floor((index-1)/2)] < arr[index]){
            [arr[Math.floor((index-1)/2)],arr[index]] = [arr[index],arr[Math.floor((index-1)/2)]]
            index = Math.floor((index-1)/2)
        }
    }
    
}